package cn.restcloud.example.controller;

import cn.restcloud.apiflow.rule.model.P_ESBProcessRuleEntry;
import cn.restcloud.framework.core.annotation.bean.BeanConfig;
import cn.restcloud.framework.core.annotation.bean.BeanType;
import cn.restcloud.framework.core.annotation.rest.MethodType;
import cn.restcloud.framework.core.annotation.rest.RestConfig;
import cn.restcloud.framework.core.context.AppContext;
import cn.restcloud.framework.core.util.DateTimeUtil;
import cn.restcloud.framework.view.base.DocAndView;
import cn.restcloud.framework.view.util.ViewUtil;

@BeanConfig(appId = "example",beanId = "VelocityTemplateRest",beanName = "视图模板使用功能示例",beanType = BeanType.CONTROLLER)
@RestConfig(url = "/rest/example/view/template")
public class VelocityTemplateRest {

	@RestConfig(configName = "获取解板后的视图模板HTML代码",method = MethodType.POST,url = "/parser")
	public DocAndView getBody(P_ESBProcessRuleEntry obj) throws Exception{
		DocAndView dv=ViewUtil.getVelocityView("ESB_VIEW_IESBBaseEvent"); //指定模板id,模板可以在API开发平台中的视图模板中进行配置
		//以下传入变量到模板中去，在模板中通过 ${变量名} 获取
		dv.put("className", "testClass");
		dv.put("creatTime", DateTimeUtil.getNow());
		dv.put("userId", AppContext.getUserId());
		String viewcode=ViewUtil.execute(dv);
		return ViewUtil.getHtmlView(viewcode);
	}
	
}
